angular.module("market",[]).config(["$stateProvider",function($stateProvider){
	$stateProvider.state("/market",{
		url:"/market",
		templateUrl:"html/market/market.html",
		css:"html/market/market.css",
		controller:"marketController"
	})
}]).controller("marketController",function($scope,$http,$rootScope){
	
	$scope.arr1=["热销榜","新品尝鲜","优选水果","卤味熟食","牛奶面包","饮料酒水",
	"休闲零食","方便速食","粮油调味","生活用品","冰激凌"];
	$scope.ajx=["bread.json","fruit.json","hot.json","sale.json"];
	$scope.num=0;
	var arr2=[
		["全部分类"],
		["全部分类"],
		["全部分类","进口水果","国产水果"],
		["全部分类"]
	]
	$scope.arr3=["全部分类"];
	//ajax请求事件
	$scope.http=function(){
		$http.get("../node/"+$scope.ajx[$scope.num]).success(function(data){
			$scope.data=data;
			//console.log(data);
			$scope.arr2=data.data;
			//console.log($scope.arr2[2].img)
			//价格最低
			$scope.low=function(){
				$scope.arr2=data.data.sort(function(a,b){
					return a.price-b.price;
				})
			}
			//价格最高
			$scope.height=function(){
				$scope.arr2=data.data.sort(function(a,b){
					return b.price-a.price;
				})
			}
			
		})
	}
	$scope.http();
	//左边li的点击事件
	$scope.click1=function(){
		//alert(this.$index);
		$(".div3_div1").css("display","none");
		$scope.num=this.$index;
		$(".market_div2_div").stop().animate({
			"top":$scope.num*3+0.2+"rem"
		},200)
		$scope.http();
		//console.log($scope.num);
		$scope.arr3=arr2[$scope.num]
		//console.log($scope.arr3);
		return $scope.num;
	}
	//console.log(4)
	
	$rootScope.arr5=[];
	//加号的点击事件
	$scope.click3=function(){
//		$scope.num1=this.$index;
//		$scope.arr2[$scope.num1].number=1;
//		console.log($scope.arr2[$scope.num1].id)
//		
//		if($rootScope.arr5.indexOf($scope.arr2[$scope.num1])==-1){
//			$rootScope.arr5.push($scope.arr2[$scope.num1]);
//		}else if($rootScope.arr5.indexOf($scope.arr2[$scope.num1])>=0){
//			for(var i=0;i<$rootScope.arr5.length;i++){
//				if($scope.arr2[$scope.num1].id==$rootScope.arr5[i].id){
//					$rootScope.arr5[i].number+=1;
//				}
//			}
//		}
//		console.log($rootScope.arr5);
		for(var i=0;i<$rootScope.arr5.length;i++){
			if(this.x.name==$rootScope.arr5[i].name){
				$rootScope.arr5[i].number++;
				return;
			}
		}
		console.log(this)
		this.x.number=1; 
		$rootScope.arr5.push(this.x)
		console.log($rootScope.arr5)
	}
	//全部分类点击事件
	$scope.fun1=function(){
		$(".div3_div1").css("display","none").css("display","block");
		$(".div3_div1_list2").css("display","none");
		$(".div3_div1_list1").css("display","flex");
	}
	//综合排序点击事件
	$scope.fun2=function(){
		$(".div3_div1").css("display","none").css("display","block")
		$(".div3_div1_list1").css("display","none");
		$(".div3_div1_list2").css("display","flex");
	}
	//蒙版的点击事件
	$scope.fun3=function($event){
		$(".div3_div1").css("display","none");
		$event.stopPropagation();
	}
	//取消ul的点击事件
	$scope.fun4=function($event){
		$event.stopPropagation();
	}

	$rootScope.a=5
	
	
	
	
	
})